@file:Suppress("NOTHING_TO_INLINE")

package cc.z8g.browser.extensions

import android.content.Context
import android.graphics.drawable.Drawable
import android.os.Build
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import java.util.Locale

/**
 * Gets a drawable from the context.
 */
inline fun Context.drawable(@DrawableRes drawableRes: Int): Drawable =
    ContextCompat.getDrawable(this, drawableRes)!!

inline fun Context.themedDrawable(
    @DrawableRes drawableRes: Int,
    @ColorInt colorInt: Int
): Drawable {
    val drawable = ContextCompat.getDrawable(this, drawableRes)!!
    drawable.setTint(colorInt)
    return drawable
}

/**
 * The preferred locale of the user.
 */
val Context.preferredLocale: Locale
    get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        resources.configuration.locales[0]
    } else {
        @Suppress("DEPRECATION")
        resources.configuration.locale
    }